﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
using TuyenSinh.BLL;

namespace TuyenSinh.Admin
{
    public partial class Major : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["Admin"] != null)
                {
                    BSchool bSchool = new BSchool();
                    DataTable dt = bSchool.GetRegion();
                    ddlRegionAdd.DataSource = dt;
                    ddlRegionAdd.DataValueField = "Id";
                    ddlRegionAdd.DataTextField = "Name";
                    ddlRegionAdd.DataBind();

                    ddlRegionAdd.Items.Insert(0, new ListItem("-- Chọn khu vực --", "-1"));

                    dt = bSchool.GetSchool(string.Empty,0,0,0,1,0);

                    ddlSchoolAdd.DataSource = dt;
                    ddlSchoolAdd.DataTextField = "Name";
                    ddlSchoolAdd.DataValueField = "Id";

                    ddlSchoolAdd.DataBind();
                    ddlSchoolAdd.Items.Insert(0, new ListItem("-- Chọn trường --", "0"));

                    BMajor bMajor = new BMajor();

                   

                    dt = bMajor.GetSesion();
                    ddlSessionAdd.DataSource = dt;
                    ddlSessionAdd.DataValueField = "Id";
                    ddlSessionAdd.DataTextField = "Name";
                    ddlSessionAdd.DataBind();

                    //Nhóm ngành
                    dt = bMajor.GetGroupMajor(0, string.Empty);
                    ddlGroupMajor.DataSource = dt;
                    ddlGroupMajor.DataTextField = "Name";
                    ddlGroupMajor.DataValueField = "Id";
                    ddlGroupMajor.DataBind();


                }
                else
                {
                    Response.Redirect("Login.aspx");
                }
            }
        }

        protected void btnSubmitCate_Click(object sender, EventArgs e)
        {

        }


        [WebMethod]
        public  static  string GetSchoolByRegion(int iRegion, int isActive)
        {
            BSchool bSchool = new BSchool();
            DataTable dt = bSchool.GetSchool(string.Empty, iRegion, 0, 0, isActive, 0);
            SchoolList SchoolLst = new SchoolList();
            if (dt.Rows.Count >0)
            {
                SchoolLst.lst = new List<SchoolItem>();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DataRow dr = dt.Rows[i];
                    SchoolItem item = new SchoolItem();
                    item.Id = dr["Id"].ToString();
                    item.Name = dr["Name"].ToString();
                    SchoolLst.lst.Add(item);
                }
            }
            return new JavaScriptSerializer().Serialize(SchoolLst);
        }

        [WebMethod]
        public static string InsertMajor(string name, string desc, int sessionId, int schoolId, int iGroupMajorId, int isActive, int isDelete)
        //public static string InsertMajor(string Name, string Desc, int FieldId, int SessionId, int isActive, int isDelete)
        {
            BMajor bMajor = new BMajor();
            bool bRes = bMajor.InsertMajor(name, desc, sessionId,schoolId,iGroupMajorId, isActive, isDelete);
            
            return  bRes == true ? "1" : "0";

        }

        [WebMethod]
        public static bool InsertMajorDetail(int iSchoolId, int iMajorId, int iNumRegister, int iTarget, float iScore, int iYear, float fNumCompetitor)
        {
            BMajor bMajor = new BMajor();
            bool bRes = bMajor.InsertMajorDetail(iSchoolId, iMajorId, iNumRegister, iTarget, iScore, iYear, fNumCompetitor);
            return bRes;
        }
    }

    public class SchoolItem
    {
        public string Id { get; set; }
        public string Name { get; set; }
    }

    [Serializable]
    public class SchoolList
    {
        public List<SchoolItem> lst { get; set; }
    }
   

}